﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@

@{
    ViewBag.Title = "UserAdd";
    Layout = "~/Views/Shared/Template.cshtml";
}

<!DOCTYPE html>
<html>
<head>
   
</head>
<body>
    <h3>员工用创建</h3>
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">账号:</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="login_name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码:</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="password" id="password" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">工号:</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="no" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="name" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱:</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="email" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机:</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="phone" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户类型:</label>
            <div class="layui-input-block">
                <input type="radio" name="user_type" value="0" class="layui-input" />员工
                <input type="radio" name="user_type" value="1" class="layui-input" />主管
                <input type="radio" name="user_type" value="2" class="layui-input" />副经理
                <input type="radio" name="user_type" value="110" class="layui-input" />董事长
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别:</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="0" class="layui-input" />女
                <input type="radio" name="sex" value="1" class="layui-input" />男
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管理员类别</label>
            <div class="layui-input-inline">
                <select name="interest" lay-filter="aihao">
                    <option value="0">全部</option>
                    <option value="1">员工</option>
                    <option value="2">管理员</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态:</label>
            <div class="layui-input-block">
                <input type="radio" name="login_flag" value="0" class="layui-input" />禁用
                <input type="radio" name="login_flag" value="1" class="layui-input" checked />启用
            </div>
        </div>
        <div class="layui-form-item">
            <input type="button" class="layui-btn layui-btn-primary layui-border" value="添加" onclick="UserAdd()" />
        </div>
    </form>
    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;
            // 提交事件
        });
        function UserAdd() {
            var model = JSON.stringify({
                    login_name : $("#login_name").val(),
                    password : $("#password").val(),
                    no : $("#no").val(),
                    name : $("#name").val(),
                    email : $("#email").val(),
                    phone : $("#phone").val(),
                    user_type : $("[name=user_type]:checked").val(),
                    sex : $("[name=sex]:checked").val(),
                    mgr_type : $("#mgr_type").val(),
                login_flag: $("[name=login_flag]:checked").val(),
                    avatar: ''
            })
            
            var token = localStorage.getItem("token")
            console.log(model)
            $.ajax({
                url: '../User/UserAddDo',
                type:'post',
                data:{ model:model,token:token},
                //contentType: 'application/json',
                success: function (res) {
                    console.log(res)
                    var res = JSON.parse(res)
                    if (res.code == 200) {
                       
                        alert("创建成功")
                        window.location.href = '/home/TestTemplate';
                    }
                    else {
                        alert("创建失败")
                    }
                }
            })
        }
    </script>

</body>
</html>
